import { computed } from "vue";

import { storeToRefs } from "pinia";

import { useGlobalStore } from "@/stores/modules/global";

const useDateFormat = () => {
	const globalStore = useGlobalStore();

	const { language } = storeToRefs(globalStore);

	const format = computed(() => {
		let result = "YYYY-MM-DD";
		switch (language.value) {
			case "ru":
				result = "DD-MM-YYYY";
				break;
			default:
				break;
		}
		return result;
	});

	const renderFormat = (format : "YYYY-MM-DD" | "YYYY-MM" | "YYYY-MM-DD HH:mm") => {
		switch (language.value) {
			case "ru":
				switch (format) {
					case "YYYY-MM-DD":
						return "DD-MM-YYYY";
					case "YYYY-MM":
						return "MM-YYYY";
					case "YYYY-MM-DD HH:mm":
						return "DD-MM-YYYY HH:mm";
					default:
						return format;
				}
			default:
				return format;
		}
	};

	return { format: format.value, renderFormat };
};

export default useDateFormat;